package com.hellobike.haxing.modules.wms.mapper;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hellobike.haxing.modules.wms.dto.SkuExtDto;
import com.hellobike.haxing.modules.wms.entity.SkuExt;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @Description: t_wms_sku_ext
 * @Author: haxing-boot
 * @Date:   2020-01-09
 * @Version: V1.0
 */
public interface SkuExtMapper extends BaseMapper<SkuExt> {

    @Select("<script>" +
            "SELECT ex.id,ex.loc_id,sp.spu_name,sk.sku_code,sk.barcode,sp.spu_code,l.loc_code,sk.id as sku_id,sk.dimension_values FROM t_sku as sk " +
            "LEFT JOIN t_spu as sp ON sp.id=sk.spu_id " +
            "LEFT JOIN t_wms_sku_ext ex ON ex.sku_id = sk.\"id\" " +
            "LEFT JOIN t_wms_location l ON l.id=ex.loc_id AND ex.warehouse_id=#{p.warehouseId} " +
            "WHERE  sk.deleted=0 AND sp.deleted=0 " +
            "<if test='p.barcode != null and p.barcode != \"\"'>" +
            "AND sk.barcode LIKE '%${p.barcode}%' " +
            "</if>" +
            "<if test='p.locCode != null and p.locCode != \"\"'>" +
            "AND l.loc_code LIKE '%${p.locCode}%' " +
            "</if>" +
            "ORDER BY sk.create_time DESC " +
            "</script>")
    IPage<SkuExtDto> pageBySkuExtDto(Page<SkuExtDto> page, @Param("p") SkuExtDto skuExt);
}
